package com.wtwd.device.controller;


import com.wtwd.device.model.vo.ResultVO;
import com.wtwd.device.constant.RespCode;
import com.wtwd.device.model.entity.SysUser;
import com.wtwd.device.model.vo.CountActivatedDeviceVO;
import com.wtwd.device.model.vo.CountAreaDeviceVO;
import com.wtwd.device.service.DeviceInfoService;
import com.wtwd.device.utils.GetCurrentSysUserInfoUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author zdl
 * @since 2021-08-03
 */
@Api(tags = "首页")
@RestController
@RequestMapping("/HomePage")
public class HomePageController {


    @Resource
    private DeviceInfoService deviceInfoService;

    @Resource
    private GetCurrentSysUserInfoUtils currentSysUserInfoUtils;

    @ApiOperation(value = "统计设备激活量", notes = "")
    @GetMapping("/countActivatedDevice")
    public ResultVO<CountActivatedDeviceVO> countActivatedDevice() {
        SysUser currentUser = currentSysUserInfoUtils.getCurrentSysUserInfo();
        Long customerId = currentUser.getCustomerId();
        if (customerId == 0) {//总部
            customerId = null;
        }
        int total = deviceInfoService.countDeviceByCustomerId(customerId);
        int activatedDeviceNum = deviceInfoService.countActivatedDeviceByCustomerId(customerId);
        CountActivatedDeviceVO countActivatedDeviceVO = new CountActivatedDeviceVO();
        countActivatedDeviceVO.setTotal(total);
        countActivatedDeviceVO.setActivatedNum(activatedDeviceNum);
        countActivatedDeviceVO.setNonactivatedNum(total - activatedDeviceNum);
        return ResultVO.success(RespCode.SUCCESS, countActivatedDeviceVO);
    }

    @ApiOperation(value = "统计区域设备数量", notes = "")
    @GetMapping("/countAreaDevice")
    public ResultVO<List<CountAreaDeviceVO>> countAreaDevice() {
        SysUser currentUser = currentSysUserInfoUtils.getCurrentSysUserInfo();
        Long customerId = currentUser.getCustomerId();
        if (customerId == 0) {//总部
            customerId = null;
        }
        return ResultVO.success(RespCode.SUCCESS, deviceInfoService.countAreaDeviceByCustomerId(customerId));
    }

}

